package org.example.controller;

import org.example.UserCovertBasic;
import org.example.bo.*;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * mapstruct 使用demo
 */
@RestController
public class TestController {

    public static void main(String[] args) {
        User user = User.builder().id(1).name("张三").createTime("2020-04-01 11:05:07").updateTime(LocalDateTime.now()).build();
        List<Object> objectList = new ArrayList<>();
        objectList.add(user);
        // 使用mapstruct
        UserVO1 userVO1 = UserCovertBasic.INSTANCE.toConvertVO1(user);
        //使用user转化成userVO3
        UserVO3 userVO3 = UserCovertBasic.INSTANCE.toConvertVO3(user);
        System.out.println(userVO3);
        objectList.add("userVO1:" + UserCovertBasic.INSTANCE.toConvertVO1(user));
        objectList.add("userVO1转换回实体类user:" + UserCovertBasic.INSTANCE.fromConvertEntity1(userVO1));
        // 输出转换结果
        objectList.add("userVO2:" + " | " + UserCovertBasic.INSTANCE.toConvertVO2(user));
        // 使用BeanUtils
        UserVO2 userVO22 = new UserVO2();
        BeanUtils.copyProperties(user, userVO22);
        objectList.add("userVO22:" + " | " + userVO22);
        System.out.println(objectList);

        User user1 = User.builder().id(2)
                .name("张三1")
                .createTime("2020-04-02 11:05:07")
                .updateTime(LocalDateTime.now()).build();
        User user2 = User.builder().id(23)
                .name("张三3")
                .createTime("2020-04-03 11:05:07")
                .updateTime(LocalDateTime.now()).build();
        List<User> list = new ArrayList<>();
        list.add(user1);
        list.add(user2);
        List<UserVO1> userVO1s = UserCovertBasic.INSTANCE.toConvertVOList(list);
        System.out.println(userVO1s);
        UserEnum userEnum = UserEnum.builder().id(2).name("你好").userTypeEnum(UserTypeEnum.DB).build();
        UserVO5 userVO5 = UserCovertBasic.INSTANCE.toConvertVO5(userEnum);
        System.out.println(userVO5);



    }
}
